﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TreeBuilder
{
	public class NodeTextChangedAction : UndoableAction
	{
		private readonly TreeNode _node;
		private readonly string _oldText;
		private readonly string _newText;

		public NodeTextChangedAction(TreeNode node, string oldText, string newText)
		{
			_node = node;
			_oldText = oldText;
			_newText = newText;
		}

		public override void Execute()
		{
			if (_node.TextBox.Text == _newText) return;

			_node.TextBox.Text = _newText;
			_node.TopCenter = _node.TopCenter;
		}

		public override void Undo()
		{
			_node.TextBox.Text = _oldText;
		}
	}
}
